﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using KPIS.GERP.GHRMS.APP.Classes;
using KPIS.GERP.GHRMS.BLL;
using KPIS.GERP.GHRMS.IBLL;
using KPIS.GERP.GHRMS.MODEL;

namespace KPIS.GERP.GHRMS.APP.App_UI.Forms
{
    public partial class PS_NonWorkingDaysEdit : System.Web.UI.Page
    {
        private Main main = new Main();
        private INonWorkingDayBLL nwdBLL = new NonWorkingDayBLL();

        protected void Page_Load(object sender, EventArgs e)
        {
            BindRepeaterYear();
            LoadDataGrid();
        }

        public void LoadDataGrid()
        {
            IList<NonWorkingDayInfo> Info = nwdBLL.ListNonWorkingDay(SelectedBgYear, 0, "", "").OrderBy(o=>o.Date).ToList();
            RadGrid1.DataSource = Info;
            RadGrid1.DataBind();
        }
        private void BindRepeaterYear()
        {
            repeaterYear.DataSource = BgYearRange;
            repeaterYear.DataBind();
        }

        private List<int> BgYearRange
        {
            get
            {
                List<int> bgYearRange = new List<int>();
                for (int i = SelectedBgYear - 10; i < SelectedBgYear + 10; i++)
                {
                    bgYearRange.Add(i);
                }
                return bgYearRange;
            }
        }

        public int SelectedBgYear
        {
            get
            {
                int bgYear;
                int bgYearNow = Convert.ToInt32(DateTime.Now.ToString("yyyy", new CultureInfo("th-TH")));
                if (DateTime.Now.Month < 10)
                {
                    bgYearNow--;
                }
                bgYear = main.ConvertNullInt(Request["BgYear"]) ?? bgYearNow;
                  
                return bgYear;
            }
        }
    }
}